/*
 *  Brno University of Technology
 *
 *  Copyright (C) 2009-2010 by Brno University of Technology and the contributors
 *
 *  Complete list of developers available at our web site:
 *
 *       http://spl.utko.feec.vutbr.cz
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/.
 */
package cz.vutbr.feec.utko.ef.core;

/**
 * The Class Random stands for random implementation of random number generator.
 * The reason why to use this class instead of java.util.Random is that this
 * pseudo random numbers generator is not very random. Therefore in future the
 * class can be replaced with better algorithms.
 * 
 * When deterministic behavior of the random number generator (e.g. for
 * debugging), change the static attribute SEED to any value different to -1.
 * Then this seed is used for initialization of java.util.Random class.
 */
public class Random {
	
	/** The random. */
	private java.util.Random rnd;
	
	/** The SEED. */
	public static long SEED = -1;

	/**
	 * Instantiates a new random.
	 */
	public Random() {
		if (SEED == -1) {
			rnd = new java.util.Random();
		} else {
			rnd = new java.util.Random(SEED++);
		}
	}

	public boolean nextBoolean() {
		return rnd.nextBoolean();
	}

	/**
	 * Next double.
	 * 
	 * @return the double
	 */
	public double nextDouble() {
		return rnd.nextDouble();
	}

	/**
	 * Next integer.
	 * 
	 * @return the integer value
	 */
	public int nextInt() {
		return rnd.nextInt();
	}

	/**
	 * Next integer.
	 * 
	 * @param i
	 *            the i
	 * 
	 * @return the integer value
	 */
	public int nextInt(int i) {
		return rnd.nextInt(i);
	}
	/**
	 * Next gauss.
	 * 
	 * @return the gauss value
	 */
	public double nextGauss() {
		return rnd.nextGaussian();
	}
	/**
	 * Next gaussCumulative.
	 * 
	 * @return the gaussCumulative value
	 */
	public double nextGaussCumulative() {
		
		double v = nextDouble();
		double value = nextGauss();
		if(v>0.5){
			value = value + (0.5-value);
		}
		
		return value;
	}
}
